package cn.boundtw2.jihe.map;

import java.util.HashMap;
import java.util.LinkedHashMap;

/*
    java.util.linkeHashMap<k,v> entends HashMap<k,v>
    Map 接口的哈希表和链接列表实现，具有可预知的迭代顺序
    底层原理：
        哈希表+链表（记录元素的顺序）
 */
public class Demo03LinkedHashMap {
    public static void main(String[] args) {
        HashMap<String, String> map1 = new HashMap<>();
        map1.put("a","a");
        map1.put("c","c");
        map1.put("b","b");
        map1.put("a","d");
        System.out.println(map1);//key不允许重复，无序{a=d, b=b, c=c}
        System.out.println("--------------------");
        LinkedHashMap<String,String> map2 = new LinkedHashMap<>();
        map2.put("a","a");
        map2.put("c","c");
        map2.put("b","b");
        map2.put("a","d");
        System.out.println(map2);//key不允许重复，有序{a=d, c=c, b=b}
    }
}
